package com.bwie.controller;

import cn.hutool.core.lang.Validator;
import com.bwie.service.TbUserService;
import com.bwie.utils.Result;
import com.bwie.vo.LoginVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * description:
 *
 * @Author zhaohaoyang
 * @Create 2025/6/6 14:06
 * @Version 1.0
 */
@RestController
@RequestMapping("/auth/index")
public class IndexController {
    @Autowired
    TbUserService tbUserService;

    /**
     * 发送手机验证码
     * @param mobile
     * @return
     */
    @PostMapping("/sendCode/{mobile}")
    public Result sendCode(@PathVariable("mobile")String mobile){
        if(!Validator.isMobile(mobile)){
            return Result.error().setMsg("手机号格式不正确");
        }
        return tbUserService.sendCode(mobile);
    }

    /**
     * 用户登录
     * @param loginVo
     * @return
     */
    @PostMapping("/login")
    public Result login(@RequestBody @Validated LoginVo loginVo){
        return tbUserService.login(loginVo);
    }
}
